// mypage/addBankcard/addBankcard.js
var util = require("../../utils/util");

Page({
  /*页面的初始数据*/
  data: {
    name: '',
    is_focus:false,
    bank_num: '',
    num: '',
    mobile:'',
    mob1: '',
    show_bank: false,
    show_ver: false,
    focus: false,
    time: 60,
    length:6,
    isFocus:false,
    Value:"",
    show_btn: false
  },
  /*生命周期函数--监听页面加载*/
  onLoad: function (options) {
    
  },
  input_name:function(e){
    this.setData({name: e.detail.value})
  },
  number_tap:function(){
    this.setData({ is_focus:true, })
  },
  number_focus:function(e){
    var that = this;
    var val = e.detail.value;
    var num = util.insertStr(util.insertStr(util.insertStr(util.insertStr(val,4," "),9," "),14," "),19," ");
    that.setData({bank_num:val,num:num})
  },
  send_bankDesc:function(){
    var that = this,name = that.data.name,bank_num=that.data.bank_num;
    
    that.setData({show_bank: true,focus: true});
  },
  send_mobile:function(){
    var that = this,mobile = that.data.mobile;
    var neg=(/^1[3456789]\d{9}$/);
    if(!neg.test(mobile)||!mobile){
      util.page_show_toast('手机号码输入有误',1500)
      return false;
    }
    that.setData({show_ver: true,isFocus: true});
    that.interval();
  },
  mobile_focus(e){
    var that = this;
    var val = e.detail.value;
    var mob1 = util.insertStr(util.insertStr(val,3," "),8," ");
    that.setData({mobile:val, mob1:mob1})
  }, 
  mobile_tap(){
    this.setData({ focus:true })
  }, 
  ver_focus(e){
    var that = this;
    var inputValue = e.detail.value;
    that.setData({ Value:inputValue })
    if(inputValue.length==6){
      util.page_show_toast('绑定成功',1500)
      setTimeout(function(){
        wx.navigateBack({
          delta: 1
        });
      },2000)
    }
  }, 
  ver_tap(){
    this.setData({ isFocus:true, })
  },
  interval:function(){
    var that = this,time=that.data.time;
    var tms=setInterval(function(){
      time--;
      that.setData({time: time})
      if(time==0){
        clearInterval(tms)
        that.setData({time: 60,show_btn: true})
      }
    },1000)
  },
  again_send:function(){
    var that = this,show_btn=that.data.show_btn;
    if(show_btn){
      //
      that.interval();
      that.setData({show_btn: false})
    }
  },
})